package com.effectivejava.composition.InheritanceNotGood;

import java.util.Collection;
import java.util.HashSet;

public class InstrumentHashSet<E> extends HashSet<E> {

	private static final long serialVersionUID = 1L;
	
	private int addCount;
	
	public InstrumentHashSet(){
		
	}

	public InstrumentHashSet(int initCap, float loadFactor){
		super(initCap, loadFactor);
	}
	
	@Override public boolean add(E e) {
		addCount++;
		//System.out.println("dongdong");
		return super.add(e);
	}
	
	@Override public boolean addAll(Collection<? extends E> c) {
		addCount += c.size();
		return super.addAll(c);
	}
	
	public int getAddCount() {
		return addCount;
	}

	public static void main(String[] args){
		InstrumentHashSet<String> test1 = new InstrumentHashSet<String>();
		test1.add("dong");
	}
}
